//
//  ShopChecksViewController.m
//  NewApp
//
//  Created by xueyan liu on 6/27/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ShopChecksViewController.h"
#import "ChecksEndViewController.h"

@interface ShopChecksViewController ()

@end

@implementation ShopChecksViewController
@synthesize titleText;
@synthesize order_id;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    selectedTime = [[NSString alloc] initWithString:@"1"];
    self.titleLabel.text = titleText;
    [self.view setFrame:CGRectMake(0, 80, 320, 480)];
    [self.view setBackgroundColor:[UIColor grayColor]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark - click button event

-(IBAction)clickChecked_1:(id)sender{

    selectedTime = @"1";
    [btCheck1 setImage:[UIImage imageNamed:@"checked_icon"] forState:UIControlStateNormal];
    [btCheck2 setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
    [btCheck3 setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
}

-(IBAction)clickChecked_2:(id)sender{

    selectedTime = @"2";
    [btCheck1 setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
    [btCheck2 setImage:[UIImage imageNamed:@"checked_icon"] forState:UIControlStateNormal];
    [btCheck3 setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
}

-(IBAction)clickChecked_3:(id)sender{
    
    selectedTime = @"3";
    [btCheck1 setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
    [btCheck2 setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
    [btCheck3 setImage:[UIImage imageNamed:@"checked_icon"] forState:UIControlStateNormal];
}

-(IBAction)clickATM:(id)sender{

    [self.engine shopCheckMsgWithID:order_id q1:selectedTime q2:@"1"];
}

-(IBAction)clickCash:(id)sender{

    [self.engine shopCheckMsgWithID:order_id q1:selectedTime q2:@"2"];
}

#pragma mark -
#pragma mark - Private methods

- (void) requestDidFinished:(RequestEngine *)reqEngine withObject:(id)object {
    
    if ([object isKindOfClass:[NSDictionary class]]) {
        NSDictionary *result = (NSDictionary *) object;
        [result retain];
        
        NSString *status = [result objectForKey:@"status"];
        NSString *msg = [result objectForKey:@"msg"];
       // NSString *order_id = [result objectForKey:@"order_id"];
        
        if ([status isEqualToString:@"1"]) {

            ChecksEndViewController *vctrl = [[ChecksEndViewController alloc] init];
            vctrl.titleText = [result objectForKey:@"top_title"];
            vctrl.msg = [msg retain];
            [self.navigationController pushViewController:vctrl animated:YES];
            [vctrl release];
        }
        
        [result release];
    }
}

@end
